package com.example.config.security.hanlder;
import com.example.util.JSONAuthentication;
import com.example.vo.ResultVoEnum;
import org.springframework.security.access.AccessDeniedException;
import org.springframework.security.web.access.AccessDeniedHandler;
import org.springframework.stereotype.Service;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 自定义访问权限不足处理器（处理认证成功的用户异常）
 * @author wsl
 */
@Service("accessDeniedHandler")
public class AccessDeniedHandlerImpl implements AccessDeniedHandler {

    @Override
    public void handle(HttpServletRequest request, HttpServletResponse response, AccessDeniedException accessDeniedException) throws IOException, ServletException {
        ResultVoEnum resultVoEnum = null;
        resultVoEnum = ResultVoEnum.USER_PERMISSION_DENIED;
        JSONAuthentication.WriteJSON(request,response, resultVoEnum);
    }
}
